home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.1 / Libraries / Intuition / other_examples / EasyReq / ez.c next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  3.0 KB  |  129 lines

  1. /***********************************************************************
  2.  *                                                                     *
  3.  *                            COPYRIGHTS                               *
  4.  *                                                                     *
  5.  *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.   *
  6.  *                                                                     *
  7.  **********************************************************************/
  8.  
  9. /* ez.c */
  10.  
  11. #include <exec/types.h>
  12. #include <intuition/intuition.h>
  13.  
  14. /* lc -L -iVINCLUDE: -iINCLATTICE: ez    */
  15.  
  16. /*
  17.  * test by passing text string, gadget string, (string) args
  18.  *    example:
  19.  *    ez "Please insert volume %s|in any drive." Retry|Cancel MyVol
  20.  *
  21.  * NOTE: This program converts '|' separators in the body text format
  22.  * string you provide to '\n', which is the (new) proper line
  23.  * separator.
  24.  */
  25.  
  26. struct IntuitionBase    *IntuitionBase;
  27. APTR            GfxBase;
  28.  
  29. struct EasyStruct myezreq = {
  30.     sizeof (struct EasyStruct), 0,
  31.     "EasyRequest Test Program",
  32.     "Usage: \"ez <text string> <gadget string> <arg1> <arg2> ...\"\n\
  33. where <text string> has '|' separators at line breaks,\n\
  34. and <gadget text> has '|' separators between gadgets.\n\
  35. The <argN> parameters are for 'printf-style'\n'%%' commands in the strings.",
  36.     "I understand.|I'll figure it out someday."
  37. };
  38.  
  39. struct EasyStruct argezreq = {
  40.     sizeof (struct EasyStruct), 0,
  41.     "From the Command Line",
  42.     "Test Line",
  43.     "Gadgets",
  44. };
  45.  
  46. void changeToNewline();
  47.  
  48. main( argc, argv )
  49. UBYTE    **argv;
  50. {
  51.     ULONG    idcmp = DISKINSERTED;
  52.     int        retval;
  53.     struct Window    *reqwindow;
  54.     struct Window    *BuildEasyRequest();
  55.  
  56.     IntuitionBase = (struct IntuitionBase *)
  57.         OpenLibrary("intuition.library", 33 );
  58.     GfxBase = (APTR) OpenLibrary("graphics.library", 33 );
  59.  
  60.     if ( IntuitionBase && GfxBase )
  61.     {
  62.     if ( argc < 2 )
  63.     {
  64. #if 1
  65.         reqwindow = BuildEasyRequest( NULL, &myezreq, 0L, 50 );
  66.         while ( (retval=SysReqHandler( reqwindow, NULL, TRUE ) ) == -2 )
  67.         {
  68.         ;
  69.         }
  70.         FreeSysRequest( reqwindow );
  71. #else
  72.         retval = EasyRequest( NULL, &myezreq, NULL, 50 );
  73. #endif
  74.     }
  75.     else
  76.     {
  77.         argezreq.es_TextFormat = argv[ 1 ];
  78.         changeToNewline( argezreq.es_TextFormat );
  79.         if ( argc >= 3 ) argezreq.es_GadgetFormat = argv[ 2 ];
  80.         retval = EasyRequestArgs( NULL, &argezreq, &idcmp, argv+3 );
  81.     }
  82.  
  83.     printf( "AFR returned %lx\n", retval );
  84.     }
  85.     else
  86.     {
  87.     puts( "can't open Intuition." );
  88.     }
  89. }
  90.  
  91. /* 
  92.  * convert '|' in text format string to newlines
  93.  */
  94. void
  95. changeToNewline( c )
  96. UBYTE    *c;
  97. {
  98.     while ( *c != '\0' )
  99.     {
  100.     if ( *c == '|' )
  101.     {
  102.         *c = '\n';
  103.     }
  104.     c++;
  105.     }
  106. }
  107.  
  108. struct Window    *
  109. BuildEasyRequest( w, ez, idcmp, arg1 )
  110. struct Window    *w;
  111. struct EasyStruct *ez;
  112. ULONG        idcmp;
  113. int        arg1;
  114. {
  115.     struct Window    *BuildEasyRequestArgs();
  116.  
  117.     return ( BuildEasyRequestArgs( w, ez, idcmp, &arg1 ) );
  118. }
  119.  
  120. EasyRequest( w, ez, ip, args )
  121. struct Window    *w;
  122. struct EasyStruct *ez;
  123. ULONG        *ip;
  124. int    args;
  125. {
  126.     printf("args at %lx\n", &args );
  127.     return ( EasyRequestArgs( w, ez, ip, &args ) );
  128. }
  129.